package org.jay.angla.onlab;

import org.jay.angla.database.PhotoMeasureDB;
import org.jay.angla.database.QuantitativeAnalusisDB;
import org.jay.angla.database.TimeScanningDB;
import org.jay.angla.database.WavelengthScanningDB;
import org.jay.angla.utils.SharePreferenceUtil;

import android.app.Application;

public class OnlabApplication extends Application {

	public static final String SP_FILE_NAME = "onlab_setting_sp";
	private static OnlabApplication mApplication;
	private PhotoMeasureDB mPhotoMeasureDB;
	private QuantitativeAnalusisDB mQuantitativeAnalusisDB;
	private TimeScanningDB mTimeScanningDB;
	private WavelengthScanningDB mWavelengthScanningDB;
	private SharePreferenceUtil mSpUtil;

	public synchronized static OnlabApplication getInstance() {
		return mApplication;
	}

	@Override
	public void onCreate() {
		// TODO Auto-generated method stub
		super.onCreate();
		mApplication = this;
		initData();
	}

	private void initData() {
		mPhotoMeasureDB = new PhotoMeasureDB(this);
		mQuantitativeAnalusisDB = new QuantitativeAnalusisDB(this);
		mTimeScanningDB = new TimeScanningDB(this);
		mWavelengthScanningDB = new WavelengthScanningDB(this);
		mSpUtil = new SharePreferenceUtil(this, SP_FILE_NAME);
	}

	public synchronized PhotoMeasureDB getPhotoMeasureDB() {
		if (mPhotoMeasureDB == null)
			mPhotoMeasureDB = new PhotoMeasureDB(this);

		return mPhotoMeasureDB;
	}

	public synchronized QuantitativeAnalusisDB getQuantitativeAnalusisDB() {
		if (mQuantitativeAnalusisDB == null)
			mQuantitativeAnalusisDB = new QuantitativeAnalusisDB(this);

		return mQuantitativeAnalusisDB;
	}

	public synchronized TimeScanningDB getTimeScanningDB() {
		if (mTimeScanningDB == null)
			mTimeScanningDB = new TimeScanningDB(this);

		return mTimeScanningDB;
	}

	public synchronized WavelengthScanningDB getWavelengthScanningDB() {
		if (mWavelengthScanningDB == null)
			mWavelengthScanningDB = new WavelengthScanningDB(this);

		return mWavelengthScanningDB;
	}

	public synchronized SharePreferenceUtil getSpUtil() {
		if (mSpUtil == null)
			mSpUtil = new SharePreferenceUtil(this, SP_FILE_NAME);
		return mSpUtil;
	}
}
